
// pipe1.c: communication over a pipe

#include "kernel/types.h"
#include "user/user.h"

int
main()
{
  int fds[2];
  char buf[100];
  int n;

  // create a pipe, with two FDs in fds[0], fds[1].
  pipe(fds);
  
  write(fds[1], "hello\n", 6);
  n = read(fds[0], buf, sizeof(buf));
  
  printf("Received:%d\n",n);


  write(1, buf, n);  
  
  close(fds[1]);
  printf("write-end of pipe has been closed\n");
  n=read(fds[0],buf,sizeof(buf));
  printf("Received:%d\n",n);

  exit(0);
}
